<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>04_员工列表练习</title>
</head>
<body>

let arr = [];

<input type="text" placeholder="请输入员工姓名" id="i1">
<input type="text" placeholder="请输入员工工资" id="i2">
<input type="text" placeholder="请输入员工岗位" id="i3">
<button onclick="addEmp()">点我添加</button>
<hr>
<table border="1">
    <caption>员工列表</caption>
    <tr>
        <th>员工姓名</th>
        <th>员工工资</th>
        <th>员工岗位</th>
    </tr>
</table>

<script>
    function addEmp(){
        let uName = document.getElementById('i1').value;
        let uSalary = document.getElementById('i2').value;
        let uJob = document.getElementById('i3').value;
        if (!uName || !uSalary || !uJob) {
            alert('请填写完整信息');
            return;
        }
        let trE = document.createElement('tr');
        let nameTd = document.createElement('td');
        let salaryTd = document.createElement('td');
        let jobTd = document.createElement('td');

        nameTd.innerHTML = uName;
        salaryTd.innerHTML = uSalary;
        jobTd.innerHTML = uJob;

        trE.append(nameTd, salaryTd, jobTd);

        let table = document.querySelector('table');
        table.append(trE);

        document.getElementById('i1').value='';
        document.getElementById('i2').value='';
        document.getElementById('i3').value='';

        arr.push({
            name: uName,
            salary: uSalary,
            job: uJob
        })


    }

</script>
</body>
</html>